<script setup lang="ts">
import { ref } from 'vue'
import { getKnowledgePage } from '@/api/consult'
import type { KnowledgeType, KnowledgeList, KnowledgeParams } from '@/types/consult'
import KnowledgeCard from './KnowledgeCard.vue'
const props = defineProps<{ type: KnowledgeType }>()
//列表加载状态 true 加载中 | false 加载完成
const loading = ref(false)
const finished = ref(false)

const list = ref<KnowledgeList>([])
const params = ref<KnowledgeParams>({
  type: props.type,
  current: 1,
  pageSize: 10,
})
const onLoad = async () => {
  const res = await getKnowledgePage(params.value)
  console.log('res:123465', res)
  if (res.data) {
    list.value.push(...res.data.rows)
    console.log('params.value.current', params.value.current)
    if (params.value.current >= res.data.pageTotal) {
      finished.value = true
    } else {
      params.value.current++
    }
    loading.value = false
  }
  console.log('res', res)
}
</script>

<template>
  <div class="knowledge-list">
    <van-list v-model:loading="loading" :finished="finished" error-text="没有更多了" @load="onLoad">
      <knowledge-card v-for="item in list" :key="item.id" :item="item"></knowledge-card>
    </van-list>
  </div>
</template>

<style lang="scss" scoped>
.knowledge-list {
  padding: 0 15px;
}
</style>
